package cn.openea.perpartner.componet.util;


import cn.openea.perpartner.common.auth.entity.LoginBody;

import lombok.extern.slf4j.Slf4j;

/**
 * @author Weird077
 * @description TODO
 * @date 2022-12-02 11:24
 */
@Slf4j
public class UserContext {
    private static final ThreadLocal<ThreadContext> contextHolder = new ThreadLocal<>();

    public static ThreadContext getContext() {
        // 初始化线程对像
        ThreadContext threadContext = contextHolder.get();
        if (threadContext == null) {
            threadContext = new ThreadContext();
            contextHolder.set(threadContext);
        }
        return threadContext;
    }

    public static void setLoginUser(LoginBody loginBody) {
        getContext().setLoginUser(loginBody);
    }

    public static void clear() {
        contextHolder.remove();
    }

    public static LoginBody getLoginUser() {

        return getContext().getLoginUser();
    }

    public static String getUserId() {

        return getContext().getUserId();
    }

    public static String getUserName() {

        return getContext().getUserName();
    }



}
